#include <iostream>
#include <podofo/podofo.h>

using namespace PoDoFo;

void HelloWorld(const char *pszFilename)
{
	PdfStreamedDocument document(pszFilename);
	PdfPainter painter;
	PdfPage *pPage;
	PdfFont *pFont;

	pPage = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
	if (!pPage)
	{
		PODOFO_RAISE_ERROR(ePdfError_InvalidHandle);
	}

	painter.SetPage(pPage);

	pFont = document.CreateFont("Arial");
	if (!pFont)
	{
		PODOFO_RAISE_ERROR(ePdfError_InvalidHandle);
	}

	pFont->SetFontSize(18.0);
	painter.SetFont(pFont);
	painter.SetColor(1.0, 0.0, 0.0);

	painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 56.69, "Hello World!");

	painter.SetColor(0.0, 1.0, 0.0);
	painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 100, "It is a test");

	painter.SetColor(0.0, 0.0, 1.0);
	painter.DrawLine(0.0, 0.0, pPage->GetPageSize().GetWidth(), pPage->GetPageSize().GetHeight());

	painter.DrawTextAligned(0, 150.0, pPage->GetPageSize().GetWidth(), "It is Center", EPdfAlignment::ePdfAlignment_Center);

	PdfImage image_data(&document);
	image_data.LoadFromFile("test.jpg");
	painter.DrawImage(100, pPage->GetPageSize().GetHeight() - 600, &image_data, (0.5), (0.5));

	painter.FinishPage();
	document.Close();
}

int main(int argc, char *argv[])
{
	HelloWorld("test.pdf");
	PdfEncodingFactory::FreeGlobalEncodingInstances();
	std::cout << "Success" << std::endl;

	return 0;
}
